// Copyright (c) 2024, the WwMusic project authors.  Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

package com.springfairy.controller;

import com.springfairy.model.MoodType;
import com.springfairy.service.MoodTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/moodtypes")
public class MoodTypeController {
    @Autowired
    private MoodTypeService moodTypeService;

    // 创建心情类型
    @PostMapping("/create")
    public ResponseEntity<MoodType> createMoodType(@RequestBody MoodType moodType) {
        MoodType created = moodTypeService.createMoodType(moodType);
        return ResponseEntity.ok(created);
    }

    // 获取所有心情类型
    @GetMapping("/list")
    public ResponseEntity<List<MoodType>> getAllMoodTypes() {
        List<MoodType> types = moodTypeService.getAllMoodTypes();
        return ResponseEntity.ok(types);
    }

    // 删除心情类型
    @PostMapping("/delete/{id}")
    public ResponseEntity<Map<String, String>> deleteMoodType(@PathVariable int id) {
        try {
            moodTypeService.deleteMoodType(id);
            Map<String, String> response = new HashMap<>();
            response.put("message", "心情类型删除成功");
            return ResponseEntity.ok(response);
        } catch (Exception e) {
            Map<String, String> response = new HashMap<>();
            response.put("message", "心情类型不存在");
            return ResponseEntity.status(404).body(response);
        }
    }
}
